import http from './http.js'

// 文档相关API
export const documentApi = {
  // 获取所有文档
  getAllDocuments() {
    return http.get('/api/documents')
  },

  // 根据ID获取文档
  getDocumentById(id) {
    return http.get(`/api/documents/${id}`)
  },

  // 根据用户ID获取文档
  getDocumentsByUserId(userId) {
    return http.get(`/api/documents/user/${userId}`)
  },

  // 根据标题搜索文档
  searchDocumentsByTitle(title) {
    return http.get(`/api/documents/search?title=${encodeURIComponent(title)}`)
  },

  // 根据内容搜索文档
  searchDocumentsByContent(content) {
    return http.get(`/api/documents/search/content/${content}`)
  },

  // 根据标签获取文档
  getDocumentsByTag(tag) {
    return http.get(`/api/documents/tag/${tag}`)
  },

  // 获取文档状态列表
  getDocumentsByStatus(status) {
    return http.get(`/api/documents/status/${status}`)
  },

  // 创建新文档
  createDocument(documentData) {
    return http.post('/api/documents', documentData)
  },

  // 更新文档
  updateDocument(id, documentData) {
    return http.put(`/api/documents/${id}`, documentData)
  },

  // 删除文档
  deleteDocument(id) {
    return http.delete(`/api/documents/${id}`)
  },

  // 更新文档状态
  updateDocumentStatus(id, status) {
    return http.put(`/api/documents/${id}/status`, { status })
  },

  // 更新文档权限
  updateDocumentPermission(id, permission) {
    return http.put(`/api/documents/${id}/permission`, { permission })
  },

  // 更新文档标签
  updateDocumentTags(id, tags) {
    return http.put(`/api/documents/${id}/tags`, { tags })
  },

  // 获取文档统计信息
  getDocumentStats() {
    return http.get('/api/documents/stats')
  }
}

// 文档上传相关API
export const documentUploadApi = {
  // 上传文档文件
  uploadDocument(formData) {
    return http.upload('/api/documentupload/upload', formData)
  },

  // 获取上传进度（如果后端支持）
  getUploadProgress(uploadId) {
    return http.get(`/api/documentupload/progress/${uploadId}`)
  },

  // 取消上传（如果后端支持）
  cancelUpload(uploadId) {
    return http.delete(`/api/documentupload/cancel/${uploadId}`)
  },

  // 批量上传文档
  batchUpload(formData) {
    return http.upload('/api/documentupload/batch', formData)
  }
}
